package database

type UserLoginInfo struct {
	Id           int
	UserName     string
	Password     string
	AvatarAdress string
}

//QueryByUserName 通过用户名查询
func QueryByUserName(uname string) (u *UserLoginInfo, err error) {
	//查询单挑记录的sql语句  ?是参数
	sqlStr := "select id,username,password,image from users where username=?;"
	//执行
	row := DB.QueryRow(sqlStr, uname)
	//拿到结果
	var id int
	var username string
	var password string
	var image string
	err = row.Scan(&id, &username, &password, &image)
	if err != nil {
		return nil, err
	}
	u = &UserLoginInfo{
		Id:           id,
		UserName:     username,
		Password:     password,
		AvatarAdress: image,
	}
	return u, nil
}

//QueryByUserId 通过用户名查询
func QueryByUserId(uid int) (u *UserLoginInfo, err error) {
	//查询单挑记录的sql语句  ?是参数
	sqlStr := "select id,username,password,image from users where id=?;"
	//执行
	row := DB.QueryRow(sqlStr, uid)
	//拿到结果
	var id int
	var username string
	var password string
	var image string
	err = row.Scan(&id, &username, &password, &image)
	if err != nil {
		return nil, err
	}
	u = &UserLoginInfo{
		Id:           id,
		UserName:     username,
		Password:     password,
		AvatarAdress: image,
	}
	return u, nil
}
